package demo.huangli.mydemosnew.logic_set_1.bolts;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import bolts.CancellationTokenSource;
import demo.huangli.mydemosnew.R;

/**
 * Created by huangli on 17/12/29.
 */

public class CancelTaskActivity extends Activity implements View.OnClickListener{

    private CancellationTokenSource cancellationTokenSource;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cancel_task);
        findViewById(R.id.btn_start_task).setOnClickListener(this);
        findViewById(R.id.btn_cancel_task).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_start_task:
                cancellationTokenSource = BoltsHelper.callCancleTask();
                break;
            case R.id.btn_cancel_task:
                if (cancellationTokenSource != null){
                    cancellationTokenSource.cancel();
                }
                break;
        }
    }
}
